<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
</head>
<body>
    <form id="uploadForm" action="/upload" method="post" enctype="multipart/form-data">
      <input type="file" name="imgFile" id="imgFile" >

      <input type="submit" value="upload">
    </form>
    <img src="" id="myimg"/>


    <script>
        $("#uploadForm").submit(function (e){
            e.preventDefault();
            let files = document.getElementById("imgFile").files;
            if(files.length>0){
                let file = files[0];
                let formDate = new FormData();
                formDate.append("imgFile",file);
                $.ajax({
                    type:"post",
                    url:"/upload",
                    data:formDate,
                    contentType:false,
                    processData:false,
                    success:function (resp){
                        document.getElementById("myimg").src = resp.message;
                    }
                })
            }else {
                alert("请选择文件");
            }
        })
    </script>
</body>
</html>